from PySide6.QtWidgets import *
from enums.WidgetType import WidgetType
from enums.ZhWidgetType import ZhWidgetType
from PySide6.QtCore import Qt


class TypeSelect(QDialog):
    def __init__(self, onSelect):
        super(TypeSelect, self).__init__()
        self.onSelect = onSelect

        self.setWindowModality(Qt.WindowModality.ApplicationModal)
        self.setWindowTitle('选择类型')
        self.setFixedSize(200, 100)
        self.mainLayout = QVBoxLayout()
        self.setLayout(self.mainLayout)

        self.comboBox = QComboBox()
        self.comboBox.addItems(ZhWidgetType.values())
        self.curSelectType = WidgetType.values()[0]
        self.comboBox.setContentsMargins(20, 20, 20, 20)
        self.comboBox.currentTextChanged.connect(self.comboxTextChange)
        self.mainLayout.addWidget(self.comboBox)

        QBtn = QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel

        self.buttonBox = QDialogButtonBox(QBtn)
        self.buttonBox.accepted.connect(self.accept)
        self.buttonBox.rejected.connect(self.reject)
        self.mainLayout.addWidget(self.buttonBox)

    def comboxTextChange(self, text):
        self.curSelectType = WidgetType[ZhWidgetType(text).name].value

    def accept(self):
        self.onSelect(self.curSelectType)
        super(TypeSelect, self).accept()
